package com.rk.kbk.controller;

import com.alibaba.fastjson.JSONArray;
import com.rk.kbk.common.JsonResp;
import com.rk.kbk.common.PubLib;
import com.rk.kbk.common.SqlToResult;
import com.rk.kbk.dao.CashRecordDao;
import com.rk.kbk.dao.UserDao;
import com.rk.kbk.dto.PageDto;
import com.rk.kbk.model.CashRecord;
import com.rk.kbk.model.User;
import com.rk.kbk.service.UserService;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.http.MediaType;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.Expression;
import javax.persistence.criteria.Predicate;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;


/**
 * @CashRecordController
 * @用户商家现金流水Controller
 * @version : Ver 1.0
 */
@CrossOrigin
@RestController
@Transactional
@RequestMapping(value="/api/cashRecord")
public class CashRecordController {
    private Logger log = Logger.getLogger(this.getClass());
    @Autowired
    private CashRecordDao cashRecordDao;
    @Autowired
    private UserDao userDao;
    @Autowired
    private SqlToResult sqlToResult;
    @Autowired
    private UserService userService;
    @PersistenceContext
    private EntityManager entityManager;

    /**
     * @param cashRecord
     * @return 返回值JsonResp
     * @添加/修改用户商家现金流水
     */
    @RequestMapping(value = "/addOrUpdateCashRecord",
            method = RequestMethod.POST,
            produces = MediaType.APPLICATION_JSON_VALUE + ";charset=UTF-8")
    public JsonResp addOrUpdateCashRecord(@RequestBody CashRecord cashRecord) {
        log.debug("添加/修改用户商家现金流水");
        cashRecordDao.save(cashRecord);
        return JsonResp.ok();
    }

    /**
     * @param cashRecords
     * @return 返回值JsonResp
     * @批量添加/修改用户商家现金流水
     */
    @RequestMapping(value = "/addOrUpdateSomeCashRecord",
            method = RequestMethod.POST,
            produces = MediaType.APPLICATION_JSON_VALUE + ";charset=UTF-8")
    public JsonResp addOrUpdateSomeCashRecord(@RequestBody List<CashRecord> cashRecords) {
        log.debug("批量添加/修改用户商家现金流水");
        cashRecordDao.save(cashRecords);
        return JsonResp.ok();
    }

    /**
     * @param cashRecordId
     * @return 返回值JsonResp
     * @获取用户商家现金流水详情-ByCashRecordId
     */
    @RequestMapping(value = "/cashRecordDetails",
            method = RequestMethod.GET,
            produces = MediaType.APPLICATION_JSON_VALUE + ";charset=UTF-8")
    public JsonResp findCashRecordDetailsByCashRecordId(Long cashRecordId) {
        log.debug("获取用户商家现金流水详情-ByCashRecordId");
        return JsonResp.ok(cashRecordDao.findOne(cashRecordId));
    }

    /**
     * @param userId     用户id
     * @param recoedType 流水类型
     * @return 返回值JsonResp
     * @获取用户商家现金流水详情展示-ByCashRecordId
     */
    @RequestMapping(value = "/cashRecordDisplay",
            method = RequestMethod.GET,
            produces = MediaType.APPLICATION_JSON_VALUE + ";charset=UTF-8")
    public JsonResp findCashRecordDetailsByUserIdAndRecoedType(Long userId, Integer recoedType, String startTime, String endTime) {
        log.debug("获取用户商家现金流水详情展示-ByCashRecordId");
        User user = userDao.findOne(userId);
        if (recoedType == 0) {
            if ("".equals(startTime) || "".equals(endTime)) {
                return JsonResp.ok(cashRecordDao.findByUser(user));
            } else {
                return JsonResp.ok(cashRecordDao.findByUserAndGmtDatetimeBetween(user, PubLib.strToDate(startTime, "yyyy-MM-dd HH:mm:ss"), PubLib.strToDate(startTime, "yyyy-MM-dd HH:mm:ss")));
            }
        } else {
            if ("".equals(startTime) || "".equals(endTime)) {
                return JsonResp.ok(cashRecordDao.findByUserAndRecoedType(user, recoedType));
            } else {
                return JsonResp.ok(cashRecordDao.findByUserAndRecoedTypeAndGmtDatetimeBetween(user, recoedType, PubLib.strToDate(startTime, "yyyy-MM-dd HH:mm:ss"), PubLib.strToDate(startTime, "yyyy-MM-dd HH:mm:ss")));
            }

        }


    }

    /**
     * @param userId    用户id
     * @param value     按钮类型
     * @param startTime 起始时间
     * @param endTime   结束时间
     * @param pageNum   第几页
     * @param pageSize  每页的条数
     * @return 返回值JsonResp
     * @分页查询用户钱包详情(jpa方式)
     */
    @RequestMapping(value = "/cashRecordDisplay2",
            method = RequestMethod.GET,
            produces = MediaType.APPLICATION_JSON_VALUE + ";charset=UTF-8")
    public JsonResp findPageAccountJpa(Integer pageNum, Integer pageSize, String startTime, String endTime, Long userId, Integer value) {
        log.debug("分页查询用户钱包详情(jpa方式)");
        //多条件排序Sort
        //Sort sort = new Sort(Sort.Direction.DESC, "createdate").and(new Sort(Sort.Direction.AES, "id"));
        //排序Sort
        Sort sort = new Sort(Sort.Direction.DESC, "gmtDatetime");
        Pageable pageable = new PageRequest(pageNum - 1, pageSize, sort);
        Page page = null;
        //Date startTime1=PubLib.strToDate(startTime,"yyyy-mm-dd hh:mm:ss");
        //Date endTime1=PubLib.strToDate(startTime,"yyyy-mm-dd hh:mm:ss");
        if (userId == null) {

        } else {
            page = cashRecordDao.findAll(          //条件分页
                    (root, criteriaQuery, cb) -> {
                        Predicate predicate = cb.conjunction();
                        List<Expression<Boolean>> expressions = predicate.getExpressions();
                        User user = userDao.findOne(userId);
                        if (user != null) {
                            expressions.add(cb.equal(root.get("user"), user));
                        }
                        if (value == 1) {
                            expressions.add(cb.equal(root.get("moneyType"), 1));
                        }
                        if (value == 2) {
                            List<Integer> list = new ArrayList<Integer>() {{
                                add(1);
                                add(2);
                            }};
                            CriteriaBuilder.In<Object> stick = cb.in(root.get("recoedType"));
                            for (Integer l : list) {
                                expressions.add(stick.value(l));
                            }
                        }
                        if (value == 3) {
                            expressions.add(cb.equal(root.get("moneyType"), 2));
                        }
                        if (!startTime.equals("")) {
                            try {
                                expressions.add(cb.greaterThanOrEqualTo(root.get("gmtDatetime"), new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(startTime)));
                            } catch (ParseException e) {
                                e.printStackTrace();
                            }
                        }
                        if (!endTime.equals("")) {
                            try {
                                expressions.add(cb.lessThanOrEqualTo(root.get("gmtDatetime"), new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(endTime)));
                            } catch (ParseException e) {
                            }
                        }


                        return predicate;
                    }, pageable);
        }

        return JsonResp.ok(new PageDto(page));
    }


    //equal: = 等于
    //notEqual: != 不等于
    //expressions.add(cb.equal(root.get("consultantType"), consultantId));

    //expressions.add(cb.equal(root.get("status"), 1));

    //like需要加 %
    //notLike
    //expressions.add(cb.like(root.get("userName"), "%"+"18759865891"+"%"));

    //greaterThanOrEqualTo: >= 大于等于
    // greaterThan: > 大于
    //expressions.add(cb.greaterThanOrEqualTo(root.get("gmtDatetime"), PubLib.strToDate("2017-03-02 14:07:29", "yyyy-MM-dd HH:mm:ss")));

    //lessThanOrEqualTo: <= 小于等于
    // lessThan: < 小于
    //expressions.add(cb.and(cb.lessThanOrEqualTo(root.get("gmtDatetime"), PubLib.strToDate("2017-03-02 14:07:29", "yyyy-MM-dd HH:mm:ss"))));

    //in
    //expressions.add(cb.in(root.get("stick")).value(0).value(1));

    //in
    //List<Integer> list = new ArrayList<Integer>(){{add(0);add(1);}};
    //expressions.add(cb.in(root.get("stick")).value(list));

    //gt: > 大于
    //expressions.add(cb.gt(root.get("stick"), 0));

    //lt: < 小于
    //expressions.add(cb.lt(root.get("stick"), 3));

    //......


    /**
     * @param recoedtype
     * @param pageNum    第几页
     * @param pageSize   每页的条数
     * @return 返回值JsonResp
     * @我的钱包账户明细
     */
    @RequestMapping(value = "/cashRecordList",
            method = RequestMethod.GET,
            produces = MediaType.APPLICATION_JSON_VALUE + ";charset=UTF-8")
    public JsonResp CashRecordList(Integer recoedtype, Integer usertype, Integer withdrawStatus, String phone, Integer pageNum, Integer pageSize) {
        log.debug("我的钱包账户明细 后台");
        Sort sort = new Sort(Sort.Direction.DESC, "gmtDatetime");
        Pageable pageable = new PageRequest(pageNum - 1, pageSize, sort);
        Page page = cashRecordDao.findAll(          //条件分页
                (root, criteriaQuery, cb) -> {
                    Predicate predicate = cb.conjunction();
                    List<Expression<Boolean>> expressions = predicate.getExpressions();
                    if (StringUtils.isNotBlank(phone)) {
                        User user = userDao.findOneByPhone(phone);
                        expressions.add(cb.equal(root.get("user"), user));
                    }
                    if (recoedtype != 0) {
                        expressions.add(cb.equal(root.get("recoedType"), recoedtype));
                    }
                    if (withdrawStatus != 0) {
                        expressions.add(cb.equal(root.get("withdrawStatus"), withdrawStatus));
                    }
                    if (usertype != 0) {
                        List<User> userList = userDao.findByUserTypeAndUserStatus(usertype, 1);
                        CriteriaBuilder.In<Object> stick = cb.in(root.get("user"));
                        for (User l : userList) {
                            expressions.add(stick.value(l));
                        }
                    }
                    return predicate;
                }, pageable);

        return JsonResp.ok(new PageDto(page));
    }

    /**
     * @param recoedType
     * @param pageNum    第几页
     * @param pageSize   每页的条数
     * @return 返回值JsonResp
     * @我的钱包账户明细
     */
    @RequestMapping(value = "/findCashRecordDetails",
            method = RequestMethod.GET,
            produces = MediaType.APPLICATION_JSON_VALUE + ";charset=UTF-8")
    public JsonResp findCashRecordDetails(Integer recoedType, Long userId, Integer pageNum, Integer pageSize) {
        log.debug("我的钱包账户明细");
        User user = userDao.findOne(userId);
        Sort sort = new Sort(Sort.Direction.DESC, "gmtDatetime");
        Pageable pageable = new PageRequest(pageNum - 1, pageSize, sort);
        Page page = cashRecordDao.findAll(          //条件分页
                (root, criteriaQuery, cb) -> {
                    Predicate predicate = cb.conjunction();
                    List<Expression<Boolean>> expressions = predicate.getExpressions();
                    expressions.add(cb.equal(root.get("user"), user));
                    if (recoedType == 1 || recoedType == 2) {//余额或押金
                        expressions.add(cb.equal(root.get("moneyType"), recoedType));
                    } else if (recoedType == 3) {//充值提现
                        CriteriaBuilder.In<Object> stick = cb.in(root.get("recoedType"));
                        List<Integer> list = new ArrayList<Integer>() {{
                            add(1);
                            add(2);
                        }};
                        for (Integer l : list) {
                            expressions.add(stick.value(l));
                        }
                    }
                    return predicate;
                }, pageable);
    /*    List<CashRecord> content = page.getContent();
        List<Map> cashRecordList = new ArrayList<>();
        for (CashRecord cashRecord1 : content) {
            Map map = new HashMap();
            map.put("title", cashRecord1.getTitle());
            map.put("transaction_num", cashRecord1.getTransactionNum());
            map.put("merchant_num", cashRecord1.getMerchantNum());
            map.put("order_type", cashRecord1.getOrderType());
            map.put("order_number", cashRecord1.getOrderNumber());
            map.put("recoed_type", cashRecord1.getRecoedType());
            map.put("recharge_type", cashRecord1.getRechargeType());
            map.put("money_type", cashRecord1.getMoneyType());
            map.put("money", cashRecord1.getMoney());
            map.put("pay_type", cashRecord1.getPayType());
            map.put("status", cashRecord1.getStatus());
            map.put("bank_name", cashRecord1.getBankName());
            map.put("bank_card_name", cashRecord1.getBankCardName());
            map.put("bank_card", cashRecord1.getBankCard());
            map.put("withdraw_status", cashRecord1.getWithdrawStatus());
            map.put("gmt_datetime", cashRecord1.getGmtDatetime());
            cashRecordList.add(map);
        }*/
        if (recoedType == 3) {
            List<CashRecord> cashRecordList2 = new ArrayList<>();
            List<CashRecord> cashRecordList = new ArrayList<>(new PageDto(page).getList());
            Iterator<CashRecord> iterator = cashRecordList.iterator();
            while (iterator.hasNext()) {
                CashRecord cashRecord1 = iterator.next();
                if(cashRecord1.getRechargeType()!=null){
                    int type = cashRecord1.getRechargeType();
                    if (type == 4 || type == 5) { //余额转押金或押金转余额 如果金额为负 清楚掉
                      /*  if (cashRecord1.getMoney().compareTo(0.00) < 0) {
                            cashRecordList2.add(cashRecord1);
                        }*/
                        cashRecordList2.add(cashRecord1);
                    }
                }
            }
            cashRecordList.removeAll(cashRecordList2);
            PageDto pageDto = new PageDto(page);
            pageDto.setList(cashRecordList);
            return JsonResp.ok(pageDto);
        } else {
            return JsonResp.ok(new PageDto(page));
        }

    }

    /**
     * @param cashRecord 分页条件
     * @param pageNum    第几页
     * @param pageSize   每页的条数
     * @return 返回值JsonResp
     * @分页查询用户商家现金流水(jpa方式)
     */
    @RequestMapping(value = "/jpa/page",
            method = RequestMethod.POST,
            produces = MediaType.APPLICATION_JSON_VALUE + ";charset=UTF-8")
    public JsonResp findPageCashRecordJpa(@RequestBody(required = false) CashRecord cashRecord, Integer pageNum, Integer pageSize) {
        log.debug("分页查询用户商家现金流水(jpa方式)");
        //多条件排序Sort
        //Sort sort = new Sort(Sort.Direction.DESC, "createdate").and(new Sort(Sort.Direction.AES, "id"));
        //排序Sort
        Sort sort = new Sort(Sort.Direction.DESC, "gmtDatetime");
        Pageable pageable = new PageRequest(pageNum - 1, pageSize, sort);
        Page page = null;
        if (null == cashRecord) {
            page = cashRecordDao.findAll(pageable); //无条件分页
        }/*else{
            final String condition =  cashRecord.getUserName();
            page = cashRecordDao.findAll( 		  //条件分页
                    (root, criteriaQuery, cb) -> {
                        Predicate predicate = cb.conjunction();
                        List<Expression<Boolean>> expressions = predicate.getExpressions();
                        if (StringUtils.isNotBlank(condition)) {
                            expressions.add(cb.like(root.<String>get("condition"), "%"+ condition +"%"));
                        }
                        return predicate;
                    }, pageable);
        }*/
//        List<CashRecord> content = page.getContent();
//        for (CashRecord cashRecord1 : content) {
//        }
        return JsonResp.ok(new PageDto(page));
    }


    /**
     * @param cashRecordId
     * @return 返回值JsonResp
     * @删除用户商家现金流水-one(永久)
     */
    @RequestMapping(value = "/deleteCashRecordOne",
            method = RequestMethod.GET,
            produces = MediaType.APPLICATION_JSON_VALUE + ";charset=UTF-8")
    public JsonResp deleteCashRecordOne(Long cashRecordId) {
        log.debug("删除用户商家现金流水-one(永久)");
        cashRecordDao.delete(cashRecordId);
        return JsonResp.ok();
    }

    /**
     * @param cashRecords
     * @return 返回值JsonResp
     * @批量删除用户商家现金流水(永久)
     */
    @RequestMapping(value = "/deleteSomeCashRecord",
            method = RequestMethod.POST,
            produces = MediaType.APPLICATION_JSON_VALUE + ";charset=UTF-8")
    public JsonResp deleteSomeCashRecord(@RequestBody List<CashRecord> cashRecords) {
        log.debug("批量删除用户商家现金流水(永久)");
        cashRecordDao.delete(cashRecords);
        return JsonResp.ok();
    }

    /**
     * @param id
     * @return 返回值JsonResp
     * @批量删除用户商家现金流水(永久)
     */
    @RequestMapping(value = "/changeStatus",
            method = RequestMethod.GET,
            produces = MediaType.APPLICATION_JSON_VALUE + ";charset=UTF-8")
    public JsonResp changeStatus(long id, int type) {
        log.debug("更新提现状态");
        CashRecord cashRecord = cashRecordDao.findOne(id);
        if (cashRecord.getWithdrawStatus() != 1) {
            return JsonResp.fa("300");
        } else {
            cashRecord.setWithdrawStatus(type);
            cashRecordDao.save(cashRecord);
        }
        return JsonResp.ok();
    }

    /**
     * @param value  类型
     * @param userId 用户id
     * @return 返回值JsonResp
     * @流水账
     */
    @RequestMapping(value = "/moneySum",
            method = RequestMethod.GET,
            produces = MediaType.APPLICATION_JSON_VALUE + ";charset=UTF-8")

    public JsonResp MoneySum(Long userId, String startTime, String endTime, Integer value) {
        log.debug("流水账");
        String sql = "";
        if (startTime.equals("") || endTime.equals("")) {
            if (value == 1) {
                sql = "select sum(money) as sum from cash_record  where user = " + userId + " and money_type=1";
            }
            if (value == 2) {
                sql = "select sum(money) as sum from cash_record  where user = " + userId + " and recoed_type in (1,2)";
            }
            if (value == 3) {
                sql = "select sum(money) as sum from cash_record  where user = " + userId + " and money_type=2";
            }
        } else {
            if (value == 1) {
                sql = "select sum(money) as sum from cash_record  where user = " + userId + " and gmt_datetime between '" + startTime + "' and '" + endTime + "' and money_type=1 ";
            }
            if (value == 2) {
                sql = "select sum(money) as sum from cash_record  where user = " + userId + " and gmt_datetime between '" + startTime + "' and '" + endTime + "' and recoed_type in (1,2) ";
            }
            if (value == 3) {
                sql = "select sum(money) as sum from cash_record  where user = " + userId + " and gmt_datetime between '" + startTime + "' and '" + endTime + "' and money_type=2 ";
            }
        }

        Object resultList = sqlToResult.getResultList(sql, "one");
        Map map = PubLib.copyObject(resultList, Map.class);
        return JsonResp.ok(map);
    }

    /**
     * @param userType   用户类型
     * @param search     模糊搜索
     * @param isRegister 审核状态
     * @return 返回值JsonResp
     * @用户总金额信息
     */
    @RequestMapping(value = "/userMoneySum",
            method = RequestMethod.GET,
            produces = MediaType.APPLICATION_JSON_VALUE + ";charset=UTF-8")

    public JsonResp UserMoneySum(Integer userType, String search, Integer isRegister) {
        log.debug("用户总金额信息");
        String sql;
        if (isRegister == -1) {
            sql = "SELECT SUM(account.all_money) as allmoney,SUM(account.block_money) as blockmoney,SUM(account.deposit_money) as depositmoney,SUM(account.block_deposit_money) as blockdepositmoney FROM account ,`user` WHERE account.`user`=`user`.id  AND `user`.user_type = " + userType + " and   user.phone like '%" + search + "%'  ";
        } else {
            sql = "SELECT SUM(account.all_money) as allmoney,SUM(account.block_money) as blockmoney,SUM(account.deposit_money) as depositmoney,SUM(account.block_deposit_money) as blockdepositmoney FROM account ,`user` WHERE account.`user`=`user`.id  AND `user`.is_register = " + isRegister + " and user_Type= " + userType + " and user.phone like '%" + search + "%'  ";
        }
        Object resultList = sqlToResult.getResultList(sql, "one");
        Map map = PubLib.copyObject(resultList, Map.class);
        return JsonResp.ok(map);
    }

    /**
     * @param userId 用户id
     * @return 返回值JsonResp
     * @银行卡信息
     */
    @RequestMapping(value = "/bankDetails",
            method = RequestMethod.GET,
            produces = MediaType.APPLICATION_JSON_VALUE + ";charset=UTF-8")

    public JsonResp bankDetails(Long userId) {
        log.debug("银行卡信息");
        String sql = "SELECT DISTINCT(bank_card),bank_card_name,bank_name FROM `cash_record` where user = " + userId + "  ";
        Object resultList = sqlToResult.getResultList(sql);
        JSONArray map = PubLib.copyObject(resultList, JSONArray.class);
        return JsonResp.ok(map);
    }

    /**
     * @param id
     * @return 返回值JsonResp
     * @设置提现通过
     */
    @RequestMapping(value = "/setPass",
            method = RequestMethod.GET,
            produces = MediaType.APPLICATION_JSON_VALUE + ";charset=UTF-8")
    public JsonResp setPass(Long id) {
        log.debug("设置提现通过");
        CashRecord c = cashRecordDao.findOne(id);
        c.setWithdrawStatus(2);
        cashRecordDao.save(c);
        return JsonResp.ok();
    }

    /**
     * @param id
     * @return 返回值JsonResp
     * @设置提现失败
     */
    @RequestMapping(value = "/setFail",
            method = RequestMethod.GET,
            produces = MediaType.APPLICATION_JSON_VALUE + ";charset=UTF-8")
    public JsonResp setFail(Long id) {
        log.debug("设置提现通过");
        CashRecord c = cashRecordDao.findOne(id);
        c.setWithdrawStatus(3);
        cashRecordDao.save(c);
        return JsonResp.ok();
    }

    /**
     * @return 返回值JsonResp
     * @主页统计
     */
    @RequestMapping(value = "/sum",
            method = RequestMethod.GET,
            produces = MediaType.APPLICATION_JSON_VALUE + ";charset=UTF-8")
    public JsonResp sum() {
        log.debug("主页统计");
        //交易总额

        String sqlone = "SELECT ((select IFNULL(sum(send_money),0)+IFNULL(sum(order_tip),0)+IFNULL(SUM(change_money),0) FROM orders WHERE order_status =4 ) + (SELECT IFNULL(SUM(pay_money),0) from order_goods WHERE order_status =7) ) as allSum  ";
        Object resultListone = sqlToResult.getResultList(sqlone, "one");
        Map mapone = PubLib.copyObject(resultListone, Map.class);
        //月交易总额
        String sqltwo = "SELECT ((select IFNULL(sum(send_money),0)+IFNULL(sum(order_tip),0)+IFNULL(SUM(change_money),0) FROM orders WHERE order_status =4 and date_format(gmt_datetime,'%Y-%m')=date_format(now(),'%Y-%m')) + (SELECT IFNULL(SUM(pay_money),0) from order_goods WHERE order_status =7 and date_format(gmt_datetime,'%Y-%m')=date_format(now(),'%Y-%m')) ) as allSumByMonth   ";
        Object resultListtwo = sqlToResult.getResultList(sqltwo, "one");
        Map maptwo = PubLib.copyObject(resultListtwo, Map.class);
        //日交易总额
        String sqlthree = "SELECT ((select IFNULL(sum(send_money),0)+IFNULL(sum(order_tip),0)+IFNULL(SUM(change_money),0) FROM orders WHERE order_status =4 and gmt_datetime>=CURDATE()) + (SELECT IFNULL(SUM(pay_money),0) from order_goods WHERE order_status =7 and gmt_datetime>=CURDATE()) ) as allSumByDay   ";
        Object resultListthree = sqlToResult.getResultList(sqlthree, "one");
        Map mapthree = PubLib.copyObject(resultListthree, Map.class);
        //订单总量
        String sqlfour = "SELECT ((select IFNULL(COUNT(id),0) from orders where order_status =4)  + (select IFNULL(COUNT(id),0) from order_goods where order_status =7)) as ordersSum ";
        Object resultListfour = sqlToResult.getResultList(sqlfour, "one");
        Map mapfour = PubLib.copyObject(resultListfour, Map.class);
        //月订单总量
        String sqlfive = "SELECT ((select IFNULL(COUNT(id),0) from orders WHERE date_format(gmt_datetime,'%Y-%m')=date_format(now(),'%Y-%m') and order_status =4)  + (select IFNULL(COUNT(id),0) from order_goods WHERE date_format(gmt_datetime,'%Y-%m')=date_format(now(),'%Y-%m') and order_status =7)) as ordersSumByMonth ";
        Object resultListfive = sqlToResult.getResultList(sqlfive, "one");
        Map mapfive = PubLib.copyObject(resultListfive, Map.class);
        //日订单总量
        String sqlsix = "SELECT ((select IFNULL(COUNT(id),0) from orders WHERE gmt_datetime>=CURDATE() and order_status =4 )  + (select IFNULL(COUNT(id),0) from order_goods WHERE gmt_datetime>=CURDATE() and order_status =7)) as ordersSumByDay ";
        Object resultListsix = sqlToResult.getResultList(sqlsix, "one");
        Map mapsix = PubLib.copyObject(resultListsix, Map.class);
        List<Map> list = new ArrayList<>();
        list.add(mapone);
        list.add(maptwo);
        list.add(mapthree);
        list.add(mapfour);
        list.add(mapfive);
        list.add(mapsix);
        return JsonResp.ok(list);
    }

    /**
     * @return 返回值JsonResp
     * @主页柱状图统计
     */
    @RequestMapping(value = "/barSum",
            method = RequestMethod.GET,
            produces = MediaType.APPLICATION_JSON_VALUE + ";charset=UTF-8")
    public JsonResp barSum(Integer sumType, Integer timeType) {
        log.debug("主页柱状图统计");
        List<Map> datemaps = new ArrayList<>();
        //交易额按天查
        if (sumType == 1 && timeType == 1) {
            String sqlone = "SELECT IFNULL(SUM(pay_money), 0) AS ordergoodssum, date(gmt_datetime) AS ordergoodstime FROM order_goods WHERE order_status = 7 AND date(gmt_datetime) >= date_sub(curdate(), INTERVAL 6 DAY) AND date(gmt_datetime) <= date_sub(curdate(), INTERVAL 0 DAY) GROUP BY date(gmt_datetime) ";
            List resultListone = (List) sqlToResult.getResultList(sqlone);
            List<Map> ordergoodsday = new ArrayList<>();
            for (Object o : resultListone) {
                Map map = PubLib.copyObject(o, Map.class);
                ordergoodsday.add(map);
            }

            String sqltwo = "SELECT( IFNULL(sum(send_money), 0) + IFNULL(sum(order_tip), 0) + IFNULL(SUM(change_money), 0)) AS ordersum,date(gmt_datetime) AS ordertime FROM orders WHERE order_status = 4 AND date(gmt_datetime) >= date_sub(curdate(), INTERVAL 6 DAY) AND date(gmt_datetime) <= date_sub(curdate(), INTERVAL 0 DAY) GROUP BY date(gmt_datetime) ";
            List resultListtwo = (List) sqlToResult.getResultList(sqltwo);
            List<Map> ordersday = new ArrayList<>();
            for (Object o : resultListtwo) {
                Map map = PubLib.copyObject(o, Map.class);
                ordersday.add(map);
            }
            //拿到最近七天的日期集合
            Date date = new Date();
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(date);
            Date date1;
            Map map = new HashMap();
            map.put("time", new SimpleDateFormat("yyyy-MM-dd").format(date));
            datemaps.add(map);
            for (int i = 1; i < 7; i++) {
                calendar.add(Calendar.DATE, -1);
                date1 = calendar.getTime();
                String a = new SimpleDateFormat("yyyy-MM-dd").format(date1);
                Map map1 = new HashMap();
                map1.put("time", a);
                datemaps.add(map1);
            }
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

            int i = 0, y = datemaps.size();

            for (; i < y; i++) {
                int m = 0, n = ordergoodsday.size();
                for (; m < n; m++) {
                    Map one = ordergoodsday.get(m);
                    if (sdf.format(new Date(Long.parseLong(one.get("ordergoodstime").toString()))).equals(datemaps.get(i).get("time").toString())) {
                        datemaps.get(i).put("sum", one.get("ordergoodssum"));
                        for (Map two : ordersday) {
                            if (sdf.format(new Date(Long.parseLong(two.get("ordertime").toString()))).equals(datemaps.get(i).get("time").toString())) {
                                System.out.print(sdf.format(new Date(Long.parseLong(two.get("ordertime").toString()))));
                                datemaps.get(i).put("sum", Double.parseDouble(one.get("ordergoodssum").toString()) + Double.parseDouble(two.get("ordersum").toString()));
                                break;
                            }
                        }
                        break;
                    }
                }
                //没找到跳出循环继续判断
                if (m == n) {
                    if(ordersday.size()==0){
                        datemaps.get(i).put("sum", 0);
                    }else {
                            for (Map two : ordersday) {
                                if (sdf.format(new Date(Long.parseLong(two.get("ordertime").toString()))).equals(datemaps.get(i).get("time").toString())) {
                                    datemaps.get(i).put("sum", two.get("ordersum").toString());
                                    break;
                                }else {
                                    datemaps.get(i).put("sum", 0);
                                }
                            }
                        }
                }
            }
        }
        //交易额按月查
        if (sumType == 1 && timeType == 2) {
            String sqlone = "SELECT MONTH(gmt_datetime)as month ,IFNULL(SUM(pay_money), 0) AS ordergoodssum FROM order_goods WHERE order_status = 7  and YEAR(gmt_datetime)=2017 GROUP BY MONTH(gmt_datetime) ";
            List resultListone = (List) sqlToResult.getResultList(sqlone);
            List<Map> ordergoodsmonth = new ArrayList<>();
            for (Object o : resultListone) {
                Map map = PubLib.copyObject(o, Map.class);
                ordergoodsmonth.add(map);
            }
            String sqltwo = "SELECT MONTH(gmt_datetime)as month,( IFNULL(sum(send_money), 0) + IFNULL(sum(order_tip), 0) + IFNULL(SUM(change_money), 0)) AS ordersum FROM orders WHERE order_status = 4 and YEAR(gmt_datetime)=2017 GROUP BY MONTH(gmt_datetime) ";
            List resultListtwo = (List) sqlToResult.getResultList(sqltwo);
            List<Map> ordersmonth = new ArrayList<>();
            for (Object o : resultListtwo) {
                Map map = PubLib.copyObject(o, Map.class);
                ordersmonth.add(map);
            }
            //拿到12个月的集合
            for (int a = 0; a < 12; a++) {
                Map map = new HashMap();
                map.put("month", a + 1);
                datemaps.add(map);
            }

            int i = 0, y = datemaps.size();
            for (; i < y; i++) {
                int m = 0, n = ordergoodsmonth.size();
                for (; m < n; m++) {
                    Map one = ordergoodsmonth.get(m);
                    if (one.get("month").toString().equals(datemaps.get(i).get("month").toString())) {
                        datemaps.get(i).put("sum", one.get("ordergoodssum"));
                        for (Map two : ordersmonth) {
                            if (two.get("month").toString().equals(datemaps.get(i).get("month").toString())) {
                                datemaps.get(i).put("sum", Double.parseDouble(one.get("ordergoodssum").toString()) + Double.parseDouble(two.get("ordersum").toString()));
                                break;
                            }
                        }
                        break;
                    }
                }
                if (m == n) {
                    if(ordersmonth.size()==0){
                        datemaps.get(i).put("sum", 0);
                    }else{
                        for (Map two : ordersmonth) {
                            if (two.get("month").toString().equals(datemaps.get(i).get("month").toString())) {
                                datemaps.get(i).put("sum", two.get("ordersum").toString());
                                break;
                            } else {
                                datemaps.get(i).put("sum", 0);
                            }
                        }
                    }

                }
            }
        }
        //交易额按季度查
        if (sumType == 1 && timeType == 3) {
            String sqlone = "SELECT (concat(FLOOR((date_format(gmt_datetime, '%m ')+2)/3)))as quarter ,IFNULL(SUM(pay_money), 0) AS ordergoodssum FROM order_goods WHERE order_status = 7 AND YEAR(gmt_datetime)=2017 group by concat(date_format(gmt_datetime, '%Y '),FLOOR((date_format(gmt_datetime, '%m ')+2)/3))";
            List resultListone = (List) sqlToResult.getResultList(sqlone);
            List<Map> ordergoodsquarter = new ArrayList<>();
            for (Object o : resultListone) {
                Map map = PubLib.copyObject(o, Map.class);
                ordergoodsquarter.add(map);
            }
            String sqltwo = "SELECT (concat(FLOOR((date_format(gmt_datetime, '%m ')+2)/3)))as quarter,( IFNULL(sum(send_money), 0) + IFNULL(sum(order_tip), 0) + IFNULL(SUM(change_money), 0)) AS ordersum FROM orders WHERE order_status = 4 AND YEAR(gmt_datetime)=2017 group by concat(date_format(gmt_datetime, '%Y '),FLOOR((date_format(gmt_datetime, '%m ')+2)/3)) ";
            List resultListtwo = (List) sqlToResult.getResultList(sqltwo);
            List<Map> ordersquarter = new ArrayList<>();
            for (Object o : resultListtwo) {
                Map map = PubLib.copyObject(o, Map.class);
                ordersquarter.add(map);
            }
            //拿到4个季度的集合
            for (int a = 0; a < 4; a++) {
                Map map = new HashMap();
                map.put("quarter", a + 1);
                datemaps.add(map);
            }

            int i = 0, y = datemaps.size();
            for (; i < y; i++) {
                int m = 0, n = ordergoodsquarter.size();
                for (; m < n; m++) {
                    Map one = ordergoodsquarter.get(m);
                    if (one.get("quarter").toString().equals(datemaps.get(i).get("quarter").toString())) {
                        datemaps.get(i).put("sum", one.get("ordergoodssum"));
                        for (Map two : ordersquarter) {
                            if (two.get("quarter").toString().equals(datemaps.get(i).get("quarter").toString())) {
                                datemaps.get(i).put("sum", Double.parseDouble(one.get("ordergoodssum").toString()) + Double.parseDouble(two.get("ordersum").toString()));
                                break;
                            }
                        }
                        break;
                    }
                }
                if (m == n) {
                    if(ordersquarter.size()==0) {
                        datemaps.get(i).put("sum", 0);
                    }else{
                        for (Map two : ordersquarter) {
                            if (two.get("quarter").toString().equals(datemaps.get(i).get("quarter").toString())) {
                                datemaps.get(i).put("sum", two.get("ordersum").toString());
                                break;
                            } else {
                                datemaps.get(i).put("sum", 0);
                            }
                        }
                    }
                }
            }
        }
        //交易额按年查
        if (sumType == 1 && timeType == 4) {
            String sqlone = "SELECT IFNULL(SUM(pay_money), 0) AS ordergoodssum, YEAR(gmt_datetime) AS ordergoodstime FROM order_goods WHERE order_status = 7 GROUP BY DATE_FORMAT(gmt_datetime,'%Y') ";
            List resultListone = (List) sqlToResult.getResultList(sqlone);
            List<Map> ordergoodsday = new ArrayList<>();
            for (Object o : resultListone) {
                Map map = PubLib.copyObject(o, Map.class);
                ordergoodsday.add(map);
            }

            String sqltwo = "SELECT( IFNULL(sum(send_money), 0) + IFNULL(sum(order_tip), 0) + IFNULL(SUM(change_money), 0)) AS ordersum,Year(gmt_datetime) AS ordertime FROM orders WHERE order_status = 4  GROUP BY DATE_FORMAT(gmt_datetime,'%Y') ";
            List resultListtwo = (List) sqlToResult.getResultList(sqltwo);
            List<Map> ordersday = new ArrayList<>();
            for (Object o : resultListtwo) {
                Map map = PubLib.copyObject(o, Map.class);
                ordersday.add(map);
            }
            //拿到最近五年的集合
            Date date = new Date();
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(date);
            Date date1;
            Map map = new HashMap();
            map.put("time", new SimpleDateFormat("yyyy").format(date));
            datemaps.add(map);
            for (int i = 1; i < 5; i++) {
                calendar.add(Calendar.YEAR, -1);
                date1 = calendar.getTime();
                String a = new SimpleDateFormat("yyyy").format(date1);
                Map map1 = new HashMap();
                map1.put("time", a);
                datemaps.add(map1);
            }
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy");

            int i = 0, y = datemaps.size();

            for (; i < y; i++) {
                int m = 0, n = ordergoodsday.size();
                for (; m < n; m++) {
                    Map one = ordergoodsday.get(m);
                    if (one.get("ordergoodstime").toString().equals(datemaps.get(i).get("time").toString())) {
                        datemaps.get(i).put("sum", one.get("ordergoodssum"));
                        for (Map two : ordersday) {
                            if (two.get("ordertime").toString().equals(datemaps.get(i).get("time").toString())) {
                                datemaps.get(i).put("sum", Double.parseDouble(one.get("ordergoodssum").toString()) + Double.parseDouble(two.get("ordersum").toString()));
                                break;
                            }
                        }
                        break;
                    }
                }
                //没找到跳出循环继续判断
                if (m == n) {
                    if(ordersday.size()==0){
                        datemaps.get(i).put("sum", 0);
                    }else {
                        for (Map two : ordersday) {
                            if (two.get("ordertime").toString().equals(datemaps.get(i).get("time").toString())) {
                                datemaps.get(i).put("sum", two.get("ordersum").toString());
                                break;
                            }else {
                                datemaps.get(i).put("sum", 0);
                            }
                        }
                    }
                }
            }
        }


        //订单量按天查
        if (sumType == 2 && timeType == 1) {
            String sqlone = "select IFNULL(COUNT(id),0) as ordergoodssum ,date(gmt_datetime) AS ordergoodstime from order_goods where order_status =7 AND date(gmt_datetime) >= date_sub(curdate(), INTERVAL 6 DAY) AND date(gmt_datetime) <= date_sub(curdate(), INTERVAL 0 DAY) GROUP BY date(gmt_datetime) ";
            List resultListone = (List) sqlToResult.getResultList(sqlone);
            List<Map> ordergoodsday = new ArrayList<>();
            for (Object o : resultListone) {
                Map map = PubLib.copyObject(o, Map.class);
                ordergoodsday.add(map);
            }
            String sqltwo = "select date(gmt_datetime) AS ordertime,(IFNULL(COUNT(id),0))as ordersum from orders where order_status =4 AND date(gmt_datetime) >= date_sub(curdate(), INTERVAL 6 DAY) AND date(gmt_datetime) <= date_sub(curdate(), INTERVAL 0 DAY) GROUP BY date(gmt_datetime) ";
            List resultListtwo = (List) sqlToResult.getResultList(sqltwo);
            List<Map> ordersday = new ArrayList<>();
            for (Object o : resultListtwo) {
                Map map = PubLib.copyObject(o, Map.class);
                ordersday.add(map);
            }
            //拿到最近七天的日期集合
            Date date = new Date();
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(date);
            Date date1;
            Map map = new HashMap();
            map.put("time", new SimpleDateFormat("yyyy-MM-dd").format(date));
            datemaps.add(map);
            for (int i = 1; i < 7; i++) {
                calendar.add(Calendar.DATE, -1);
                date1 = calendar.getTime();
                String a = new SimpleDateFormat("yyyy-MM-dd").format(date1);
                Map map1 = new HashMap();
                map1.put("time", a);
                datemaps.add(map1);
            }
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            int i = 0, y = datemaps.size();

            for (; i < y; i++) {
                int m = 0, n = ordergoodsday.size();
                for (; m < n; m++) {
                    Map one = ordergoodsday.get(m);
                    if (sdf.format(new Date(Long.parseLong(one.get("ordergoodstime").toString()))).equals(datemaps.get(i).get("time").toString())) {
                        datemaps.get(i).put("sum", one.get("ordergoodssum"));
                        for (Map two : ordersday) {
                            if (sdf.format(new Date(Long.parseLong(two.get("ordertime").toString()))).equals(datemaps.get(i).get("time").toString())) {
                                datemaps.get(i).put("sum", Long.parseLong(one.get("ordergoodssum").toString()) + Long.parseLong(two.get("ordersum").toString()));
                                break;
                            }
                        }
                        break;
                    }
                }
                if (m == n) {
                    if(ordersday.size()==0){
                        datemaps.get(i).put("sum", 0);
                    }else{
                        for (Map two : ordersday) {
                            if (sdf.format(new Date(Long.parseLong(two.get("ordertime").toString()))).equals(datemaps.get(i).get("time").toString())) {
                                datemaps.get(i).put("sum", two.get("ordersum").toString());
                                break;
                            } else {
                                datemaps.get(i).put("sum", 0);
                            }
                        }
                    }

                }
            }
        }

        //订单量按月查
        if (sumType == 2 && timeType == 2) {
            String sqlone = "select MONTH(gmt_datetime)as month ,IFNULL(COUNT(id),0) as ordergoodssum from order_goods where order_status =7 AND YEAR(gmt_datetime)=2017 GROUP BY MONTH(gmt_datetime) ";
            List resultListone = (List) sqlToResult.getResultList(sqlone);
            List<Map> ordergoodsmonth = new ArrayList<>();
            for (Object o : resultListone) {
                Map map = PubLib.copyObject(o, Map.class);
                ordergoodsmonth.add(map);
            }
            String sqltwo = "select MONTH(gmt_datetime)as month,(IFNULL(COUNT(id),0))as ordersum from orders where order_status =4 AND YEAR(gmt_datetime)=2017 GROUP BY MONTH(gmt_datetime) ";
            List resultListtwo = (List) sqlToResult.getResultList(sqltwo);
            List<Map> ordersmonth = new ArrayList<>();
            for (Object o : resultListtwo) {
                Map map = PubLib.copyObject(o, Map.class);
                ordersmonth.add(map);
            }
            //拿到12个月的集合
            for (int a = 0; a < 12; a++) {
                Map map = new HashMap();
                map.put("month", a + 1);
                datemaps.add(map);
            }
            int i = 0, y = datemaps.size();
            for (; i < y; i++) {
                int m = 0, n = ordergoodsmonth.size();
                for (; m < n; m++) {
                    Map one = ordergoodsmonth.get(m);
                    if (one.get("month").toString().equals(datemaps.get(i).get("month").toString())) {
                        datemaps.get(i).put("sum", one.get("ordergoodssum"));
                        for (Map two : ordersmonth) {
                            if (two.get("month").toString().equals(datemaps.get(i).get("month").toString())) {
                                datemaps.get(i).put("sum", Double.parseDouble(one.get("ordergoodssum").toString()) + Double.parseDouble(two.get("ordersum").toString()));
                                break;
                            }
                        }
                        break;
                    }
                }
                if (m == n) {
                    if(ordersmonth.size()==0){
                        datemaps.get(i).put("sum", 0);
                    }else{
                        for (Map two : ordersmonth) {
                            if (two.get("month").toString().equals(datemaps.get(i).get("month").toString())) {
                                datemaps.get(i).put("sum", two.get("ordersum").toString());
                                break;
                            } else {
                                datemaps.get(i).put("sum", 0);
                            }
                        }
                    }
                }
            }
        }

        //订单量按季度查
        if (sumType == 2 && timeType == 3) {
            String sqlone = "select (concat(FLOOR((date_format(gmt_datetime, '%m ')+2)/3)))as quarter ,IFNULL(COUNT(id),0) as ordergoodssum from order_goods where order_status =7 AND YEAR(gmt_datetime)=2017 group by concat(date_format(gmt_datetime, '%Y '),FLOOR((date_format(gmt_datetime, '%m ')+2)/3))";
            List resultListone = (List) sqlToResult.getResultList(sqlone);
            List<Map> ordergoodsquarter = new ArrayList<>();
            for (Object o : resultListone) {
                Map map = PubLib.copyObject(o, Map.class);
                ordergoodsquarter.add(map);
            }

            String sqltwo = "select (concat(FLOOR((date_format(gmt_datetime, '%m ')+2)/3)))as quarter,(IFNULL(COUNT(id),0))as ordersum from orders where order_status =4 AND YEAR(gmt_datetime)=2017 group by concat(date_format(gmt_datetime, '%Y '),FLOOR((date_format(gmt_datetime, '%m ')+2)/3)) ";
            List resultListtwo = (List) sqlToResult.getResultList(sqltwo);
            List<Map> ordersquarter = new ArrayList<>();
            for (Object o : resultListtwo) {
                Map map = PubLib.copyObject(o, Map.class);
                ordersquarter.add(map);
            }
            //拿到4个季度的集合
            for (int a = 0; a < 4; a++) {
                Map map = new HashMap();
                map.put("quarter", a + 1);
                datemaps.add(map);
            }
            int i = 0, y = datemaps.size();
            for (; i < y; i++) {
                int m = 0, n = ordergoodsquarter.size();
                for (; m < n; m++) {
                    Map one = ordergoodsquarter.get(m);
                    if (one.get("quarter").toString().equals(datemaps.get(i).get("quarter").toString())) {
                        datemaps.get(i).put("sum", one.get("ordergoodssum"));
                        for (Map two : ordersquarter) {
                            if (two.get("quarter").toString().equals(datemaps.get(i).get("quarter").toString())) {
                                datemaps.get(i).put("sum", Double.parseDouble(one.get("ordergoodssum").toString()) + Double.parseDouble(two.get("ordersum").toString()));
                                break;
                            }
                        }
                        break;
                    }
                }
                if (m == n) {
                    if(ordersquarter.size()==0){
                        datemaps.get(i).put("sum", 0);
                    }else{
                        for (Map two : ordersquarter) {
                            if (two.get("quarter").toString().equals(datemaps.get(i).get("quarter").toString())) {
                                datemaps.get(i).put("sum", two.get("ordersum").toString());
                                break;
                            } else {
                                datemaps.get(i).put("sum", 0);
                            }
                        }
                    }
                }

            }
        }
        //订单量按年查
        if (sumType == 2 && timeType == 4) {
            String sqlone = "select YEAR(gmt_datetime)as ordergoodstime ,IFNULL(COUNT(id),0) as ordergoodssum from order_goods where order_status =7 GROUP BY DATE_FORMAT(gmt_datetime,'%Y') ";
            List resultListone = (List) sqlToResult.getResultList(sqlone);
            List<Map> ordergoodsday = new ArrayList<>();
            for (Object o : resultListone) {
                Map map = PubLib.copyObject(o, Map.class);
                ordergoodsday.add(map);
            }

            String sqltwo = "select YEAR(gmt_datetime) AS ordertime,(IFNULL(COUNT(id),0))as ordersum from orders where order_status =4 GROUP BY DATE_FORMAT(gmt_datetime,'%Y') ";
            List resultListtwo = (List) sqlToResult.getResultList(sqltwo);
            List<Map> ordersday = new ArrayList<>();
            for (Object o : resultListtwo) {
                Map map = PubLib.copyObject(o, Map.class);
                ordersday.add(map);
            }
            //拿到最近五年的集合
            Date date = new Date();
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(date);
            Date date1;
            Map map = new HashMap();
            map.put("time", new SimpleDateFormat("yyyy").format(date));
            datemaps.add(map);
            for (int i = 1; i < 5; i++) {
                calendar.add(Calendar.YEAR, -1);
                date1 = calendar.getTime();
                String a = new SimpleDateFormat("yyyy").format(date1);
                Map map1 = new HashMap();
                map1.put("time", a);
                datemaps.add(map1);
            }
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy");

            int i = 0, y = datemaps.size();

            for (; i < y; i++) {
                int m = 0, n = ordergoodsday.size();
                for (; m < n; m++) {
                    Map one = ordergoodsday.get(m);
                    if (one.get("ordergoodstime").toString().equals(datemaps.get(i).get("time").toString())) {
                        datemaps.get(i).put("sum", one.get("ordergoodssum"));
                        for (Map two : ordersday) {
                            if (two.get("ordertime").toString().equals(datemaps.get(i).get("time").toString())) {
                                datemaps.get(i).put("sum", Double.parseDouble(one.get("ordergoodssum").toString()) + Double.parseDouble(two.get("ordersum").toString()));
                                break;
                            }
                        }
                        break;
                    }
                }
                //没找到跳出循环继续判断
                if (m == n) {
                    if(ordersday.size()==0){
                        datemaps.get(i).put("sum", 0);
                    }else {
                        for (Map two : ordersday) {
                            if (two.get("ordertime").toString().equals(datemaps.get(i).get("time").toString())) {
                                datemaps.get(i).put("sum", two.get("ordersum").toString());
                                break;
                            }else {
                                datemaps.get(i).put("sum", 0);
                            }
                        }
                    }
                }
            }
        }
        return JsonResp.ok(datemaps);
    }
}



